package cn.tedu.submarine;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;

public class World extends JPanel {
    public static final int WIDTH = 641;  //画面宽
    public static final int HEIGHT = 479; //画面高

    private Battleship ship = new Battleship();
    private SeaObject[] submarines = {
            new ObserveSubmarine(),
            new TorpedoSubmarine (),
            new MineSubmarine(),
    };
    private SeaObject[] thunders = {
            new Torpedo(120,50),
            new Mine(260,100)
    };
    private Bomb[] bombs = {
            new Bomb(200,190)
    };

    public void action(){

    }

    // 重写paint
    public void paint(Graphics g){
        Images.sea.paintIcon(null,g,0,0); //画海洋图
        ship.paintImage(g); //画战舰
        for (int i=0;i<submarines.length;i++){
            submarines[i].paintImage(g);  //画潜艇
        }
        for (int i=0;i<thunders.length;i++){
            thunders[i].paintImage(g);  //画雷
        }
        for (int i=0;i<bombs.length;i++){
            bombs[i].paintImage(g);  //画炸弹
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        World world = new World();
        world.setFocusable(true);
        frame.add(world);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(WIDTH+16, HEIGHT+39);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true); //设置窗口可见   尽快调用paint方法

        world.action();
    }
}
